package com.anbinh.doctor;

import java.util.List;

import android.app.ActionBar;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.AutoCompleteTextView;
import android.widget.TextView;

import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.ActionMode;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.widget.SearchView;
import com.anbinh.doctor.fragment.FragmentMonth;
import com.anbinh.doctor.fragment.account.FragmentAccount;
import com.anbinh.doctor.fragment.account.FragmentAccountInfo;
import com.anbinh.doctor.fragment.account.FragmentAddAssistant;
import com.anbinh.doctor.fragment.account.FragmentAddBaiviet;
import com.anbinh.doctor.fragment.account.FragmentAddBangcap;
import com.anbinh.doctor.fragment.account.FragmentAddBanggia;
import com.anbinh.doctor.fragment.account.FragmentAddChucDanh;
import com.anbinh.doctor.fragment.account.FragmentAddChucvu;
import com.anbinh.doctor.fragment.account.FragmentAddChuyenkhoa;
import com.anbinh.doctor.fragment.account.FragmentAddHiephoi;
import com.anbinh.doctor.fragment.account.FragmentAddLocation;
import com.anbinh.doctor.fragment.account.FragmentAddNgonngu;
import com.anbinh.doctor.fragment.account.FragmentAddPermission;
import com.anbinh.doctor.fragment.account.FragmentAssistantDetailt;
import com.anbinh.doctor.fragment.account.FragmentAssistantList;
import com.anbinh.doctor.fragment.account.FragmentBangGia;
import com.anbinh.doctor.fragment.account.FragmentCommentDetailt;
import com.anbinh.doctor.fragment.account.FragmentDoctorInfoExtend;
import com.anbinh.doctor.fragment.account.FragmentEditBangcap;
import com.anbinh.doctor.fragment.account.FragmentEditBanggia;
import com.anbinh.doctor.fragment.account.FragmentEditChucvu;
import com.anbinh.doctor.fragment.account.FragmentEditHiephoi;
import com.anbinh.doctor.fragment.account.FragmentImagePager;
import com.anbinh.doctor.fragment.account.FragmentImages;
import com.anbinh.doctor.fragment.account.FragmentListComment;
import com.anbinh.doctor.fragment.account.FragmentListLocation;
import com.anbinh.doctor.fragment.account.FragmentListService;
import com.anbinh.doctor.fragment.account.FragmentListServiceChild;
import com.anbinh.doctor.fragment.benhnhan.FragmentAddBieuHien;
import com.anbinh.doctor.fragment.benhnhan.FragmentAddFamilyMedicalHistory;
import com.anbinh.doctor.fragment.benhnhan.FragmentAddListMedicalHistory;
import com.anbinh.doctor.fragment.benhnhan.FragmentAddNote;
import com.anbinh.doctor.fragment.benhnhan.FragmentAddPatients;
import com.anbinh.doctor.fragment.benhnhan.FragmentBieuhien;
import com.anbinh.doctor.fragment.benhnhan.FragmentFamilyMedicalHistory;
import com.anbinh.doctor.fragment.benhnhan.FragmentImagePagerPatients;
import com.anbinh.doctor.fragment.benhnhan.FragmentImagesPatients;
import com.anbinh.doctor.fragment.benhnhan.FragmentListAppoitMent;
import com.anbinh.doctor.fragment.benhnhan.FragmentListMedicalHistory;
import com.anbinh.doctor.fragment.benhnhan.FragmentListNote;
import com.anbinh.doctor.fragment.benhnhan.FragmentListPatients;
import com.anbinh.doctor.fragment.benhnhan.FragmentPatientDetailt;
import com.anbinh.doctor.fragment.benhnhan.FragmentPatientSearch;
import com.anbinh.doctor.fragment.clinic.FragmentAddDoctor;
import com.anbinh.doctor.fragment.clinic.FragmentAddPhongkham;
import com.anbinh.doctor.fragment.clinic.FragmentClinicAddLichKham;
import com.anbinh.doctor.fragment.clinic.FragmentClinicAppointmentDetailt;
import com.anbinh.doctor.fragment.clinic.FragmentClinicEditLichKham;
import com.anbinh.doctor.fragment.clinic.FragmentClinicLichhen;
import com.anbinh.doctor.fragment.clinic.FragmentClinicLichkham;
import com.anbinh.doctor.fragment.clinic.FragmentClinicMessages;
import com.anbinh.doctor.fragment.clinic.FragmentClinicMessagesDetailt;
import com.anbinh.doctor.fragment.clinic.FragmentClinicMessagesReply;
import com.anbinh.doctor.fragment.clinic.FragmentClinicMessagesResultSearch;
import com.anbinh.doctor.fragment.clinic.FragmentClinicResultSearch;
import com.anbinh.doctor.fragment.clinic.FragmentClinicSendMessages;
import com.anbinh.doctor.fragment.clinic.FragmentDoctorDetailt;
import com.anbinh.doctor.fragment.clinic.FragmentDoctorList;
import com.anbinh.doctor.fragment.clinic.benhnhan.FragmentClinicListPatients;
import com.anbinh.doctor.fragment.lichhen.FragmentAddTamhuy;
import com.anbinh.doctor.fragment.lichhen.FragmentAppointmentDetailt;
import com.anbinh.doctor.fragment.lichhen.FragmentBookAppointment;
import com.anbinh.doctor.fragment.lichhen.FragmentResultSearch;
import com.anbinh.doctor.fragment.lichkham.FragmentAddLichKham;
import com.anbinh.doctor.fragment.lichkham.FragmentEditLichKham;
import com.anbinh.doctor.fragment.tinnhan.FragmentMessagesDetailt;
import com.anbinh.doctor.fragment.tinnhan.FragmentMessagesReply;
import com.anbinh.doctor.fragment.tinnhan.FragmentMessagesResultSearch;
import com.anbinh.doctor.fragment.tinnhan.FragmentSendMessages;
import com.anbinh.doctor.model.ResponseServices.Item;
import com.anbinh.doctor.utils.IRcallBak;
import com.anbinh.doctor.utils.Utils;

public class DetailtActivity extends SherlockFragmentActivity implements
		IRcallBak, SearchView.OnQueryTextListener,
		SearchView.OnSuggestionListener {

	/** Called when the activity is first created. */
	private int mOptionMenu;
	private String mTitle;
	private boolean isEdit = false;
	private int mOptionSend = 0;
	private boolean isCustomBar = false;
	private int tabSelectMoth;

	private TextView lblTitle;
	private TextView lblAction;
	private View lineTitle;
	private TextView lblMonth;
	private boolean isShowDeleteLK;
	private SearchView searchView;
	private ActionMode mMode;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// Check if no view has focus:

		final Intent intent = getIntent();
		mTitle = intent.getStringExtra(Utils.TITLE);
		mOptionMenu = intent.getIntExtra(Utils.KEY, 0);
		isCustomBar = intent.getBooleanExtra(Utils.CUSTOMBAR, false);
		tabSelectMoth = intent.getIntExtra(Utils.KEY_SELECT_MONTH, 0);
		if (isCustomBar) {
			getSupportActionBar()
					.setDisplayOptions(
							ActionBar.DISPLAY_SHOW_CUSTOM
									| ActionBar.DISPLAY_SHOW_HOME);
			getSupportActionBar().setCustomView(R.layout.taskbar_update_data);
			lblTitle = (TextView) findViewById(R.id.title);
			lblAction = (TextView) findViewById(R.id.lblCapnhat);
			lblTitle.setText(mTitle);
		}

		if (tabSelectMoth == Utils.EXIST_MONTH) {

			getSupportActionBar()
					.setDisplayOptions(
							ActionBar.DISPLAY_SHOW_CUSTOM
									| ActionBar.DISPLAY_SHOW_HOME);
			getSupportActionBar().setCustomView(R.layout.taskbar);
			lblMonth = (TextView) findViewById(R.id.lblChuyenKhoaName);
			lblMonth.setText(String.format(
					getResources().getString(R.string.thang),
					Utils.getCurrentMonth()));
			lineTitle = (View) findViewById(R.id.lineTitle);
			lineTitle.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Bundle bundle = new Bundle();
					bundle.putInt(Utils.KEY, Utils.LICHHEN_SELECT_MONTH);
					bundle.putString(Utils.TITLE,
							getResources().getString(R.string.chon_thang));
					if (mOptionMenu == R.id.lich_hen_doctor) {
						bundle.putInt(Utils.REQUEST_CODE,
								Utils.SELECT_MONTH_LICH_HEN);
					} else {
						bundle.putInt(Utils.REQUEST_CODE,
								Utils.SELECT_MONTH_LICH_KHAM);
					}
					Utils.getNewIntent(DetailtActivity.this, bundle);
				}
			});

		}

		hideKeyboard();
		setContentView(R.layout.detailt_activity);
		getSupportActionBar().setIcon(R.drawable.ic_back);
		getSupportActionBar().setTitle(mTitle);
		getSupportActionBar().setDisplayShowHomeEnabled(true);
		getSupportActionBar().setHomeButtonEnabled(true);

		switch (mOptionMenu) {
		case R.id.add_family_medical:
			final boolean isUpdate1 = intent.getBooleanExtra(Utils.KEY_UPDATE,
					false);
			getSupportFragmentManager()
					.beginTransaction()
					.replace(
							R.id.fragment_detailt_container,
							FragmentAddFamilyMedicalHistory
									.newInstance(isUpdate1), Utils.TAG_CHILD)
					.addToBackStack(null).commit();
			if (isUpdate1) {
				lblAction.setText(getResources().getString(R.string.cap_nhat));
			} else {
				lblAction.setText(getResources().getString(R.string.them));
			}
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					FragmentAddFamilyMedicalHistory.newInstance(isUpdate1)
							.onPostBienhien(isUpdate1);
				}
			});
			break;
		case R.id.them_lich_su_kham:
			final boolean isUpdate2 = intent.getBooleanExtra(Utils.KEY_UPDATE,
					false);
			getSupportFragmentManager()
					.beginTransaction()
					.replace(
							R.id.fragment_detailt_container,
							FragmentAddListMedicalHistory
									.newInstance(isUpdate2), Utils.TAG_CHILD)
					.addToBackStack(null).commit();
			if (isUpdate2) {
				lblAction.setText(getResources().getString(R.string.cap_nhat));
			} else {
				lblAction.setText(getResources().getString(R.string.them));
			}
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					FragmentAddListMedicalHistory.newInstance(isUpdate2)
							.onPostBienhien(isUpdate2);
				}
			});
			break;
		case R.id.them_ghi_chu:
			final boolean isUpdate3 = intent.getBooleanExtra(Utils.KEY_UPDATE,
					false);
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentAddNote.newInstance(isUpdate3),
							Utils.TAG_CHILD).addToBackStack(null).commit();
			if (isUpdate3) {
				lblAction.setText(getResources().getString(R.string.cap_nhat));
			} else {
				lblAction.setText(getResources().getString(R.string.them));
			}
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					FragmentAddNote.newInstance(isUpdate3).onPostBienhien(
							isUpdate3);
				}
			});
			break;
		case R.id.them_bac_si:
			final boolean isUpdate4 = intent.getBooleanExtra(Utils.KEY_UPDATE,
					false);
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentAddDoctor.newInstance(intent.getExtras()),
							Utils.TAG_CHILD).addToBackStack(null).commit();
			if (isUpdate4) {
				lblAction.setText(getResources().getString(R.string.cap_nhat));
			} else {
				lblAction.setText(getResources().getString(R.string.them));
			}
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					FragmentAddDoctor.newInstance(intent.getExtras()).pustData(
							isUpdate4);
				}
			});
			break;
		case Utils.ADD_PATIENT:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentAddPatients.newInstance(), Utils.TAG_CHILD)
					.addToBackStack(null).commit();
			lblAction.setText(getResources().getString(R.string.them));
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					FragmentAddPatients.newInstance().pustData();
				}
			});
			break;
		case R.id.ghi_chu:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentListNote.newInstance(), Utils.TAG_CHILD)
					.addToBackStack(null).commit();
			break;
		case Utils.SEARCH_BENH_NHAN:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(
							R.id.fragment_detailt_container,
							FragmentPatientSearch.newInstance(intent
									.getExtras().getString(Utils.KEY_SEARCH)),
							Utils.TAG_CHILD).addToBackStack(null).commit();
			break;
		case R.id.lich_hen_kham:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentListAppoitMent.newInstance(),
							Utils.TAG_CHILD).addToBackStack(null).commit();

			break;
		case R.id.tin_nhan_doctor:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentClinicMessages.newInstance(),
							Utils.TAG_CHILD).addToBackStack(null).commit();

			break;
		case R.id.lich_hen_doctor:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentClinicLichhen.newInstance(),
							Utils.TAG_CHILD).addToBackStack(null).commit();

			break;
		case R.id.benh_nhan_doctor:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentClinicListPatients.newInstance(),
							Utils.TAG_CHILD).addToBackStack(null).commit();

			break;
		case R.id.lich_su_kham_chua_benh:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentListMedicalHistory.newInstance(),
							Utils.TAG_CHILD).addToBackStack(null).commit();

			break;
		case R.id.lich_su_benh_cua_gia_dinh:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentFamilyMedicalHistory.newInstance(),
							Utils.TAG_CHILD).addToBackStack(null).commit();

			break;
		case R.id.hinh_anh:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentImagesPatients.newInstance(),
							Utils.TAG_CHILD).addToBackStack(null).commit();
			break;
		case Utils.SEARCH_MESSAGE:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(
							R.id.fragment_detailt_container,
							FragmentMessagesResultSearch.newInstance(intent
									.getStringExtra(Utils.KEY_SEARCH)),
							Utils.TAG_CHILD).addToBackStack(null).commit();
			break;
		case Utils.SEARCH_MESSAGE_DOCTOR:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(
							R.id.fragment_detailt_container,
							FragmentClinicMessagesResultSearch
									.newInstance(intent
											.getStringExtra(Utils.KEY_SEARCH)),
							Utils.TAG_CHILD).addToBackStack(null).commit();
			break;
		case R.id.send_message:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentSendMessages.newInstance(), Utils.TAG_CHILD)
					.addToBackStack(null).commit();
			break;

		case R.id.send_message_doctor:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentClinicSendMessages.newInstance(),
							Utils.TAG_CHILD).addToBackStack(null).commit();
			break;

		case R.id.reply_message:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentMessagesReply.newInstance(),
							Utils.TAG_CHILD).addToBackStack(null).commit();
			break;
		case R.id.reply_message_doctor:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentClinicMessagesReply.newInstance(),
							Utils.TAG_CHILD).addToBackStack(null).commit();
			break;
		case R.id.message_detailt:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(
							R.id.fragment_detailt_container,
							FragmentMessagesDetailt.newInstance(intent
									.getExtras()), Utils.TAG_CHILD)
					.addToBackStack(null).commit();
			break;
		case R.id.message_detailt_doctor:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(
							R.id.fragment_detailt_container,
							FragmentClinicMessagesDetailt.newInstance(intent
									.getExtras()), Utils.TAG_CHILD)
					.addToBackStack(null).commit();
			break;

		case Utils.LICHHEN_SELECT_MONTH:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentMonth.newInstance(), Utils.TAG_CHILD)
					.addToBackStack(null).commit();
			break;
		case R.id.cac_van_de_suc_khoe:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentBieuhien.newInstance(), Utils.TAG_CHILD)
					.addToBackStack(null).commit();
			break;
		case R.id.them_bieu_hien:
			final boolean isUpdate = intent.getBooleanExtra(Utils.KEY_UPDATE,
					false);
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentAddBieuHien.newInstance(isUpdate),
							Utils.TAG_CHILD).addToBackStack(null).commit();
			if (isUpdate) {
				lblAction.setText(getResources().getString(R.string.cap_nhat));
			} else {
				lblAction.setText(getResources().getString(R.string.them));
			}
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					FragmentAddBieuHien.newInstance(isUpdate).onPostBienhien(
							isUpdate);
				}
			});
			break;

		case R.id.dia_diem_kham:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentListLocation.newInstance(), Utils.TAG_CHILD)
					.addToBackStack(null).commit();
			break;
		case R.id.form_them_diem_kham:

			final int requestCode = intent.getIntExtra(Utils.REQUEST_CODE, 0);
			if (requestCode == Utils.UPDATE_LOCATION) {
				lblAction.setText(getResources().getString(R.string.cap_nhat));
			} else {
				lblAction.setText(getResources().getString(R.string.them));
			}
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					if (requestCode == Utils.UPDATE_LOCATION) {
						FragmentAddLocation.newInstance(0).onUpData();
					} else {
						FragmentAddLocation.newInstance(0).onAddData();
					}
				}
			});
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentAddLocation.newInstance(requestCode),
							Utils.TAG_CHILD).addToBackStack(null).commit();
			break;
		case R.id.thong_tin_them:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentDoctorInfoExtend.newInstance(),
							Utils.TAG_CHILD).addToBackStack(null).commit();
			break;

		case R.id.thong_tin_ca_nhan:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentAccountInfo.newInstance(), Utils.TAG_CHILD)
					.addToBackStack(null).commit();
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					FragmentAccountInfo.newInstance().updateInfo();
				}
			});

			break;
		case Utils.DOCTOR_DETAILT:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentDoctorDetailt.newInstance(),
							Utils.TAG_CHILD).addToBackStack(null).commit();
			break;
		case R.id.quan_ly_bacsi:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentDoctorList.newInstance(), Utils.TAG_CHILD)
					.addToBackStack(null).commit();
			break;
		case R.id.quan_ly_tro_ly:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentAssistantList.newInstance(),
							Utils.TAG_CHILD).addToBackStack(null).commit();

			break;
		case R.id.them_tro_ly:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(
							R.id.fragment_detailt_container,
							FragmentAddAssistant.newInstance(intent.getExtras()),
							Utils.TAG_CHILD).addToBackStack(null).commit();
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					FragmentAddAssistant.newInstance(intent.getExtras())
							.updateInfo();
				}
			});
			break;
		case Utils.ASSISTANT_DETAILT:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentAssistantDetailt.newInstance(),
							Utils.TAG_CHILD).addToBackStack(null).commit();

			break;
		case Utils.SET_PERMISSION:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentAddPermission.newInstance(),
							Utils.TAG_CHILD).addToBackStack(null).commit();

			lblAction.setText(getResources().getString(R.string.them));
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					FragmentAddPermission.newInstance().pushPermission();
				}
			});
			break;
		case R.id.tao_lich_kham:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentAddLichKham.newInstance(), Utils.TAG_CHILD)
					.addToBackStack(null).commit();
			lblAction.setText(getResources().getString(R.string.them));
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					FragmentAddLichKham.newInstance().onPushData();
				}
			});

			break;
		case R.id.tao_lich_kham_doctor:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentClinicAddLichKham.newInstance(),
							Utils.TAG_CHILD).addToBackStack(null).commit();
			lblAction.setText(getResources().getString(R.string.them));
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					FragmentClinicAddLichKham.newInstance().onPushData();
				}
			});

			break;
		case Utils.EDIT_LICH_KHAM:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentEditLichKham.newInstance(), Utils.TAG_CHILD)
					.addToBackStack(null).commit();
			lblAction.setText(getResources().getString(R.string.cap_nhat));
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					FragmentEditLichKham.newInstance().checkUpdate();
				}
			});

			break;
		case Utils.EDIT_LICH_KHAM_DOCTOR:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentClinicEditLichKham.newInstance(),
							Utils.TAG_CHILD).addToBackStack(null).commit();
			lblAction.setText(getResources().getString(R.string.cap_nhat));
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					FragmentClinicEditLichKham.newInstance().checkUpdate();
				}
			});

			break;
		case R.id.bang_cap:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentAddBangcap.newInstance(), Utils.TAG_CHILD)
					.addToBackStack(null).commit();
			lblAction.setText(getResources().getString(R.string.them));
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					FragmentAddBangcap.newInstance().addCertificate();
				}
			});

			break;
		case R.id.chuc_vu:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentAddChucvu.newInstance(), Utils.TAG_CHILD)
					.addToBackStack(null).commit();
			lblAction.setText(getResources().getString(R.string.them));
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					FragmentAddChucvu.newInstance().addPosition();
				}
			});

			break;
		case R.id.chuc_danh:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentAddChucDanh.newInstance(), Utils.TAG_CHILD)
					.addToBackStack(null).commit();
			lblAction.setText(getResources().getString(R.string.them));
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					FragmentAddChucDanh.newInstance().pushSpecialList();
				}
			});

			break;
		case R.id.phong_kham:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentAddPhongkham.newInstance(), Utils.TAG_CHILD)
					.addToBackStack(null).commit();
			lblAction.setText(getResources().getString(R.string.them));
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					FragmentAddPhongkham.newInstance().pushClinicType();
				}
			});

			break;
		case Utils.EDIT_CHUCVU:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentEditChucvu.newInstance(), Utils.TAG_CHILD)
					.addToBackStack(null).commit();
			lblAction.setText(getResources().getString(R.string.cap_nhat));
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					FragmentEditChucvu.newInstance().updatePosition();
				}
			});
			break;
		case Utils.EDIT_BANGCAP:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentEditBangcap.newInstance(), Utils.TAG_CHILD)
					.addToBackStack(null).commit();
			lblAction.setText(getResources().getString(R.string.cap_nhat));
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					FragmentEditBangcap.newInstance().updateBangcap();
				}
			});
			break;
		case R.id.chuyen_khoa:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(
							R.id.fragment_detailt_container,
							FragmentAddChuyenkhoa.newInstance(intent
									.getExtras()), Utils.TAG_CHILD)
					.addToBackStack(null).commit();
			lblAction.setText(getResources().getString(R.string.cap_nhat));
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					FragmentAddChuyenkhoa.newInstance(intent.getExtras())
							.pushSpecialList();
				}
			});
			break;
		case R.id.bang_gia:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentBangGia.newInstance(), Utils.TAG_CHILD)
					.addToBackStack(null).commit();

			break;
		case R.id.them_bang_gia:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentAddBanggia.newInstance(), Utils.TAG_CHILD)
					.addToBackStack(null).commit();
			lblAction.setText(getResources().getString(R.string.them));
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					FragmentAddBanggia.newInstance().pushBangGia();
				}
			});
			break;
		case Utils.EDIT_BANGGIA:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentEditBanggia.newInstance(), Utils.TAG_CHILD)
					.addToBackStack(null).commit();
			lblAction.setText(getResources().getString(R.string.cap_nhat));
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					FragmentEditBanggia.newInstance().pushBangGia();
				}
			});
			break;

		case R.id.hiep_hoi_chuyen_khoa:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentAddHiephoi.newInstance(), Utils.TAG_CHILD)
					.addToBackStack(null).commit();
			lblAction.setText(getResources().getString(R.string.them));
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					FragmentAddHiephoi.newInstance().addHiephoi();
				}
			});
			break;
		case Utils.EDIT_HIEPHOI:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentEditHiephoi.newInstance(), Utils.TAG_CHILD)
					.addToBackStack(null).commit();
			lblAction.setText(getResources().getString(R.string.cap_nhat));
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					FragmentEditHiephoi.newInstance().editHiephoi();
				}
			});
			break;
		case R.id.bai_viet:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentAddBaiviet.newInstance(intent.getExtras()),
							Utils.TAG_CHILD).addToBackStack(null).commit();
			lblAction.setText(getResources().getString(R.string.cap_nhat));
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					FragmentAddBaiviet.newInstance(intent.getExtras())
							.addBaiviet();
				}
			});
			break;
		case Utils.EDIT_BAIVIET:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentAddBaiviet.newInstance(intent.getExtras()),
							Utils.TAG_CHILD).addToBackStack(null).commit();
			lblAction.setText(getResources().getString(R.string.cap_nhat));
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					FragmentAddBaiviet.newInstance(intent.getExtras())
							.addBaiviet();
				}
			});
			break;
		case R.id.quang_li_hinh_anh:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentImages.newInstance(), Utils.TAG_CHILD)
					.addToBackStack(null).commit();
			break;
		case Utils.VIEW_IMG:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(
							R.id.fragment_detailt_container,
							FragmentImagePager.newInstance(FragmentImages
									.newInstance().getmPosition()),
							Utils.TAG_CHILD).addToBackStack(null).commit();
			break;
		case Utils.VIEW_IMG_PATIENT:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(
							R.id.fragment_detailt_container,
							FragmentImagePagerPatients
									.newInstance(FragmentImagesPatients
											.newInstance().getmPosition()),
							Utils.TAG_CHILD).addToBackStack(null).commit();
			break;
		case R.id.dang_ki_dich_vu:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentListService.newInstance(), Utils.TAG_CHILD)
					.addToBackStack(null).commit();
			break;
		case Utils.SERVICE_CHILD:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentListServiceChild.newInstance(),
							Utils.TAG_CHILD).addToBackStack(null).commit();
			lblAction.setText(getResources().getString(R.string.cap_nhat));
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					List<Item> mList = FragmentListServiceChild.newInstance()
							.getListService();
					if (mList != null && mList.size() > 0) {
						FragmentListServiceChild.newInstance().pushService();
					}
				}
			});
			break;
		case R.id.ngon_ngu:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentAddNgonngu.newInstance(), Utils.TAG_CHILD)
					.addToBackStack(null).commit();
			lblAction.setText(getResources().getString(R.string.cap_nhat));
			lblAction.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					FragmentAddNgonngu.newInstance().pushSpecialList();
				}
			});
			break;
		case R.id.quang_ly_binh_luan:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentListComment.newInstance(), Utils.TAG_CHILD)
					.addToBackStack(null).commit();

			break;
		case Utils.APPOINTMENT_DETAILT:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(
							R.id.fragment_detailt_container,
							FragmentAppointmentDetailt.newInstance(intent
									.getExtras()), Utils.TAG_CHILD)
					.addToBackStack(null).commit();

			break;
		case Utils.APPOINTMENT_DETAILT_DOCTOR:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(
							R.id.fragment_detailt_container,
							FragmentClinicAppointmentDetailt.newInstance(intent
									.getExtras()), Utils.TAG_CHILD)
					.addToBackStack(null).commit();

			break;

		case Utils.CREATE_APPOINTMENT:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(
							R.id.fragment_detailt_container,
							FragmentBookAppointment.newInstance(intent
									.getExtras()), Utils.TAG_CHILD)
					.addToBackStack(null).commit();

			break;
		case Utils.CREATE_APPOINTMENT_DOCTOR:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(
							R.id.fragment_detailt_container,
							FragmentClinicAppointmentDetailt.newInstance(intent
									.getExtras()), Utils.TAG_CHILD)
					.addToBackStack(null).commit();

			break;

		case Utils.COMMENT_DETAILT:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentCommentDetailt.newInstance(),
							Utils.TAG_CHILD).addToBackStack(null).commit();

			break;
		case Utils.TAM_HOAN:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentAddTamhuy.newInstance(), Utils.TAG_CHILD)
					.addToBackStack(null).commit();

			break;
		case Utils.SEARCH_LICH_HEN:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(
							R.id.fragment_detailt_container,
							FragmentResultSearch.newInstance(intent
									.getStringExtra(Utils.KEY_SEARCH)),
							Utils.TAG_CHILD).addToBackStack(null).commit();

			break;
		case Utils.SEARCH_LICH_HEN_DOCTOR:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(
							R.id.fragment_detailt_container,
							FragmentClinicResultSearch.newInstance(intent
									.getStringExtra(Utils.KEY_SEARCH)),
							Utils.TAG_CHILD).addToBackStack(null).commit();

			break;
		case Utils.PATIENT_DETAILT:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(
							R.id.fragment_detailt_container,
							FragmentPatientDetailt.newInstance(intent
									.getExtras()), Utils.TAG_CHILD)
					.addToBackStack(null).commit();

			break;
		case R.id.lich_kham_doctor:
			getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.fragment_detailt_container,
							FragmentClinicLichkham.newInstance(),
							Utils.TAG_CHILD).addToBackStack(null).commit();

			break;

		}

	}

	public void pickFile(int requestCode) {
		Intent intent = new Intent(Intent.ACTION_PICK);
		intent.setType("image/*");
		startActivityForResult(intent, requestCode);
	}

	public static String getRealPathFromURI(Context context, Uri contentURI) {
		if ("file".equalsIgnoreCase(contentURI.getScheme())) {
			return contentURI.getPath();
		}
		String result = "";
		String[] projection = { "_data" };
		Cursor cursor = context.getContentResolver().query(contentURI,
				projection, null, null, null);
		if (cursor == null) { // Source is Dropbox or other similar local file
								// path
			result = contentURI.getPath();
		} else if (cursor.moveToFirst()) {
			int idx = cursor.getColumnIndex("_data");
			result = cursor.getString(idx);
			cursor.close();
		}
		return result;
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (data == null)
			return;
		switch (requestCode) {
		case Utils.ADD_PATIENT:
			FragmentClinicListPatients.newInstance().onResetData();
			FragmentClinicListPatients.newInstance().onLoadData();
		break;
		case Utils.SELECT_MONTH_LICH_KHAM:

			lblMonth.setText(String.format(
					getResources().getString(R.string.thang),
					data.getStringExtra(Utils.TIME)));

			int selectMonth = Integer.parseInt(data.getStringExtra(Utils.TIME));
			if (selectMonth == Integer.parseInt(Utils.getCurrentMonth())) {
				FragmentClinicLichkham.newInstance().onDisplayTime(selectMonth,
						Integer.parseInt(Utils.getCurrentDay()) - 1);
			} else {
				FragmentClinicLichkham.newInstance().onDisplayTime(selectMonth,
						0);
			}

			break;
		case Utils.SELECT_MONTH_LICH_HEN:

			lblMonth.setText(String.format(
					getResources().getString(R.string.thang),
					data.getStringExtra(Utils.TIME)));
			int selectMonth1 = Integer
					.parseInt(data.getStringExtra(Utils.TIME));
			if (selectMonth1 == Integer.parseInt(Utils.getCurrentMonth())) {
				FragmentClinicLichhen.newInstance().onDisplayTime(selectMonth1,
						Integer.parseInt(Utils.getCurrentDay()) - 1);
			} else {
				FragmentClinicLichhen.newInstance().onDisplayTime(selectMonth1,
						0);
			}

			break;

		case Utils.LICH_KHAM_CLINIC:
			FragmentClinicLichkham.newInstance().onloadData();
			break;
		case Utils.ONRESUME_LICHHEN:
			FragmentClinicLichhen.newInstance().onLoadData();
			Utils.showMessage(DetailtActivity.this, "Loadding...");
			break;
		case Utils.UP_IMAGE_DOCTOR:
			FragmentDoctorDetailt.newInstance().updateInfo(data);
			break;
		case Utils.REQ_EDIT_AVATAR_ASSISTION:
			FragmentAssistantDetailt.newInstance().updateInfo(data);
			break;
		case Utils.EDIT_LICH_KHAM_DOCTOR:
			FragmentClinicLichkham.newInstance().onloadData();
			break;
		case Utils.ADD_NOTE:
			FragmentListNote.newInstance().onLoadData();
			break;
		case Utils.ADD_DOCTOR:
			FragmentDoctorList.newInstance().onLoadData();
			break;
		case Utils.RESUME_PRICE:
			FragmentBangGia.newInstance().onLoadData();
			break;
		case Utils.THEM_LICH_SU_KHAM:
			FragmentListMedicalHistory.newInstance().onLoadData();
			break;
		case Utils.ADD_FAMILY_MEDICAL_HIS:
			FragmentFamilyMedicalHistory.newInstance().onLoadData();
			break;
		case Utils.ONRESUME_BIEU_HIEN:
			FragmentBieuhien.newInstance().onLoadData();

			break;

		case Utils.ADD_IMAGES_PATIENTS:
			FragmentImagesPatients.newInstance().showDialogUpload(data);
			break;

		case Utils.ATTACH_FILE_SEND_MESSAFE:
			FragmentSendMessages.newInstance().setIntentFile(data);
			break;
		case Utils.ATTACH_FILE_SEND_MESSAFE_DOCTOR:
			FragmentClinicSendMessages.newInstance().setIntentFile(data);
			break;
		case Utils.ATTACH_FILE_REPLY:
			FragmentMessagesReply.newInstance().setIntentFile(data);

			break;
		case Utils.ATTACH_FILE_REPLY_DOCTOR:
			FragmentClinicMessagesReply.newInstance().setIntentFile(data);

			break;
		case Utils.ADD_LOCATION:
			FragmentListLocation.newInstance().onResetData();
			FragmentListLocation.newInstance().onLoadData();
			break;
		case Utils.SELECT_PHONE_CONTACT:
			FragmentBookAppointment.newInstance(null).setPhone(
					Utils.getContactPhone(data, DetailtActivity.this));
			break;
		case Utils.SELECT_PHONE_CONTACT_ADDDOCTOR:
			FragmentAddDoctor.newInstance(null).setPhone(
					Utils.getContactPhone(data, DetailtActivity.this));
			break;
		case Utils.SELECT_PHONE_CONTACT_ADD_PATIENT:
			FragmentAddPatients.newInstance().setPhone(
					Utils.getContactPhone(data, DetailtActivity.this));
			break;
		case Utils.SELECT_PHONE_CONTACT_ADD_ASSISTANT:
			FragmentAddAssistant.newInstance(null).onSetPhone(
					Utils.getContactPhone(data, DetailtActivity.this));
			break;
		case Utils.RELOAD_ASSISTIANT:
			FragmentAssistantList.newInstance().onLoadData();
			break;
		case Utils.UPDATE_LOCATION:
			FragmentListLocation.newInstance().onResetData();
			FragmentListLocation.newInstance().onLoadData();
			break;
		case Utils.RESUME_EXTRA_INFO:
			FragmentDoctorInfoExtend.newInstance().onLoadData();
			break;
		case Utils.REQ_EDIT_AVATAR:
			FragmentAccount.newInstance().updateInfo(data);
			break;
		case Utils.REQ_UPLOADIMG:
			FragmentImages.newInstance().updateInfo(data);
			break;
		}

	}

	private void hideKeyboard() {
		// Check if no view has focus:
		View view = this.getCurrentFocus();
		if (view != null) {
			InputMethodManager inputManager = (InputMethodManager) this
					.getSystemService(Context.INPUT_METHOD_SERVICE);
			inputManager.hideSoftInputFromWindow(view.getWindowToken(),
					InputMethodManager.HIDE_NOT_ALWAYS);
		}
	}

	@Override
	public boolean onMenuItemSelected(int featureId, MenuItem item) {
		Bundle bundle = new Bundle();
		switch (item.getItemId()) {

		case android.R.id.home:
			finish();
			break;
		case R.id.delete_lich_kham:
			if (isShowDeleteLK) {
				isShowDeleteLK = false;
			} else {
				isShowDeleteLK = true;
			}
			FragmentClinicLichkham.newInstance().onShowDelete(isShowDeleteLK);
			break;
			
		case R.id.them_hinh_anh:
			pickFile(Utils.ADD_IMAGES_PATIENTS);
			break;
		case R.id.attach_file_reply:
			Utils.pickFile(DetailtActivity.this, Utils.ATTACH_FILE_REPLY);
			break;
		case R.id.attach_file_reply_doctor:
			Utils.pickFile(DetailtActivity.this, Utils.ATTACH_FILE_REPLY_DOCTOR);
			break;
		case R.id.attach_file_sendmessage:
			Utils.pickFile(DetailtActivity.this, Utils.ATTACH_FILE_SEND_MESSAFE);
			break;
		case R.id.attach_file_sendmessage_doctor:
			Utils.pickFile(DetailtActivity.this,
					Utils.ATTACH_FILE_SEND_MESSAFE_DOCTOR);
			break;
		case R.id.update_doctor:
			bundle.putInt(Utils.KEY, R.id.them_bac_si);
			bundle.putString(Utils.TITLE,
					getResources().getString(R.string.cap_nhat_bac_si));
			bundle.putBoolean(Utils.CUSTOMBAR, true);
			bundle.putBoolean(Utils.KEY_UPDATE, true);

			bundle.putInt(Utils.REQUEST_CODE, Utils.ADD_DOCTOR);

			Utils.getNewIntent(DetailtActivity.this, bundle);
			break;
			
		case Utils.ADD_PATIENT_DOCTOR:
			bundle.putInt(Utils.KEY, Utils.ADD_PATIENT);
			bundle.putString(Utils.TITLE,
					getResources().getString(R.string.them_benh_nhan));
			bundle.putBoolean(Utils.CUSTOMBAR, true);
			bundle.putInt(Utils.REQUEST_CODE, Utils.ADD_PATIENT);

			Utils.getNewIntentToPatient(DetailtActivity.this, bundle);
			break;
		case R.id.update_assistiant:
			bundle.putInt(Utils.KEY, R.id.them_tro_ly);
			bundle.putString(Utils.TITLE,
					getResources().getString(R.string.cap_nhat_tro_ly));
			bundle.putBoolean(Utils.CUSTOMBAR, true);
			bundle.putBoolean(Utils.KEY_UPDATE, true);

			bundle.putInt(Utils.REQUEST_CODE, Utils.ADD_DOCTOR);

			Utils.getNewIntent(DetailtActivity.this, bundle);
			break;
		case R.id.them_bac_si:
			bundle.putInt(Utils.KEY, R.id.them_bac_si);
			bundle.putString(Utils.TITLE,
					getResources().getString(R.string.them_bac_si));
			bundle.putBoolean(Utils.CUSTOMBAR, true);
			bundle.putInt(Utils.REQUEST_CODE, Utils.ADD_DOCTOR);

			Utils.getNewIntent(DetailtActivity.this, bundle);
			break;
		case R.id.send_message_doctor:
			bundle.putInt(Utils.KEY, R.id.send_message_doctor);
			bundle.putString(Utils.TITLE,
					getResources().getString(R.string.gui_tin_nhan));
			bundle.putInt(Utils.REQUEST_CODE, Utils.SEND_MESSAGES_DOCTOR);
			bundle.putBoolean(Utils.CUSTOMBAR, false);
			Utils.getNewIntent(DetailtActivity.this, bundle);
			break;
		case R.id.them_ghi_chu:
			bundle.putInt(Utils.KEY, R.id.them_ghi_chu);
			bundle.putString(Utils.TITLE,
					getResources().getString(R.string.the_ghi_chu));
			bundle.putBoolean(Utils.CUSTOMBAR, true);
			bundle.putInt(Utils.REQUEST_CODE, Utils.ADD_NOTE);

			Utils.getNewIntent(DetailtActivity.this, bundle);
			break;
		case R.id.add_family_medical:
			bundle.putInt(Utils.KEY, R.id.add_family_medical);
			bundle.putString(Utils.TITLE,
					getResources().getString(R.string.lich_su_benh_cua_gd));
			bundle.putBoolean(Utils.CUSTOMBAR, true);
			bundle.putInt(Utils.REQUEST_CODE, Utils.ADD_FAMILY_MEDICAL_HIS);

			Utils.getNewIntent(DetailtActivity.this, bundle);
			break;
		case R.id.them_lich_su_kham:
			bundle.putInt(Utils.KEY, R.id.them_lich_su_kham);
			bundle.putString(Utils.TITLE,
					getResources().getString(R.string.them_lich_kham));
			bundle.putBoolean(Utils.CUSTOMBAR, true);
			bundle.putInt(Utils.REQUEST_CODE, Utils.THEM_LICH_SU_KHAM);

			Utils.getNewIntent(DetailtActivity.this, bundle);
			break;
		case R.id.tao_lich_kham_doctor:
			bundle.putInt(Utils.KEY, R.id.tao_lich_kham_doctor);
			bundle.putString(Utils.TITLE,
					getResources().getString(R.string.them_lich_kham));
			bundle.putBoolean(Utils.CUSTOMBAR, true);
			bundle.putInt(Utils.REQUEST_CODE, Utils.LICH_KHAM_CLINIC);

			Utils.getNewIntent(DetailtActivity.this, bundle);
			break;

		case R.id.reply_message:
			bundle.putInt(Utils.KEY, R.id.reply_message);
			bundle.putString(Utils.TITLE,
					getResources().getString(R.string.tra_loi));
			bundle.putBoolean(Utils.CUSTOMBAR, false);
			bundle.putInt(Utils.REQUEST_CODE, Utils.REPLY_PATIENT);
			Utils.getNewIntent(DetailtActivity.this, bundle);
			break;
		case R.id.reply_message_doctor:
			bundle.putInt(Utils.KEY, R.id.reply_message_doctor);
			bundle.putString(Utils.TITLE,
					getResources().getString(R.string.tra_loi));
			bundle.putBoolean(Utils.CUSTOMBAR, false);
			bundle.putInt(Utils.REQUEST_CODE, Utils.REPLY_PATIENT_DOCTOR);
			Utils.getNewIntent(DetailtActivity.this, bundle);
			break;
		case R.id.dia_diem_kham:
			bundle.putInt(Utils.KEY, R.id.form_them_diem_kham);
			bundle.putString(Utils.TITLE,
					getResources().getString(R.string.them_diem_kham));
			bundle.putBoolean(Utils.CUSTOMBAR, true);
			bundle.putInt(Utils.REQUEST_CODE, Utils.ADD_LOCATION);

			Utils.getNewIntent(DetailtActivity.this, bundle);
			break;
		case R.id.them_tro_ly:
			bundle.putInt(Utils.KEY, R.id.them_tro_ly);
			bundle.putString(Utils.TITLE,
					getResources().getString(R.string.them_tro_ly));
			bundle.putBoolean(Utils.CUSTOMBAR, true);
			bundle.putBoolean(Utils.KEY_UPDATE, false);

			bundle.putInt(Utils.REQUEST_CODE, Utils.RELOAD_ASSISTIANT);

			Utils.getNewIntent(DetailtActivity.this, bundle);
			break;
		case R.id.edit_location_address:
			if (isEdit) {
				isEdit = false;
			} else {
				isEdit = true;
			}
			FragmentListLocation.newInstance().showEdit(isEdit);
			break;
		case R.id.cac_van_de_suc_khoe:
			bundle.putInt(Utils.KEY, R.id.them_bieu_hien);
			bundle.putString(Utils.TITLE,
					getResources().getString(R.string.them_bieu_hien));
			bundle.putBoolean(Utils.CUSTOMBAR, true);
			bundle.putInt(Utils.REQUEST_CODE, Utils.ONRESUME_BIEU_HIEN);
			Utils.getNewIntent(DetailtActivity.this, bundle);
			break;
		case R.id.edit_location_price:
			if (isEdit) {
				isEdit = false;
			} else {
				isEdit = true;
			}
			FragmentBangGia.newInstance().showEdit(isEdit);
			break;
		case R.id.bang_gia:

			bundle.putInt(Utils.KEY, R.id.them_bang_gia);
			bundle.putString(Utils.TITLE,
					getResources().getString(R.string.them_bang_gia));
			bundle.putBoolean(Utils.CUSTOMBAR, true);
			bundle.putInt(Utils.REQUEST_CODE, Utils.RESUME_PRICE);
			Utils.getNewIntent(DetailtActivity.this, bundle);
			break;
		case R.id.quang_li_hinh_anh:
			pickFile(Utils.REQ_UPLOADIMG);
			break;

		}
		return super.onMenuItemSelected(featureId, item);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		switch (mOptionMenu) {
		case R.id.dia_diem_kham:
			menu.add(0, R.id.dia_diem_kham, Menu.NONE, mTitle)
					.setIcon(R.drawable.ic_add)
					.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
			menu.add(0, R.id.edit_location_address, Menu.NONE, mTitle)
					.setIcon(R.drawable.ic_edit)
					.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
			break;
		case R.id.hinh_anh:
			menu.add(0, R.id.them_hinh_anh, Menu.NONE,
					getResources().getString(R.string.them))
					.setIcon(R.drawable.ic_add)
					.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
			break;
		case R.id.benh_nhan_doctor:
			menu.add(0, Utils.ADD_PATIENT_DOCTOR, Menu.NONE,
					getResources().getString(R.string.them))
					.setIcon(R.drawable.ic_add)
					.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
			break;
		case R.id.ghi_chu:
			menu.add(0, R.id.them_ghi_chu, Menu.NONE,
					getResources().getString(R.string.them))
					.setIcon(R.drawable.ic_add)
					.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
			break;
		case R.id.tin_nhan_doctor:
			searchView = new SearchView(getSupportActionBar()
					.getThemedContext());
			searchView.setQueryHint("Tên bệnh nhân");
			searchView.setOnQueryTextListener(this);
			searchView.setOnSuggestionListener(this);

			menu.add(0, R.id.send_message_doctor, Menu.NONE,
					getResources().getString(R.string.them))
					.setIcon(R.drawable.ic_send_messages)
					.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

			menu.add(1, Utils.SEARCH_LICH_HEN, Menu.NONE, "Tìm kiếm")
					.setIcon(R.drawable.ic_search)
					.setActionView(searchView)
					.setShowAsAction(
							MenuItem.SHOW_AS_ACTION_IF_ROOM
									| MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
			setStyleSearch();

			break;

		case R.id.lich_hen_doctor:

			searchView = new SearchView(getSupportActionBar()
					.getThemedContext());
			searchView.setQueryHint("Tên bệnh nhân hoặc mã cuộc hẹn");
			searchView.setOnQueryTextListener(this);
			searchView.setOnSuggestionListener(this);
			menu.add(1, Utils.SEARCH_LICH_HEN, Menu.NONE, "Tìm kiếm")
					.setIcon(R.drawable.ic_search)
					.setActionView(searchView)
					.setShowAsAction(
							MenuItem.SHOW_AS_ACTION_IF_ROOM
									| MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
			setStyleSearch();
			break;
		case R.id.lich_kham_doctor:
			menu.add(0, R.id.tao_lich_kham_doctor, Menu.NONE,
					getResources().getString(R.string.them))
					.setIcon(R.drawable.ic_add)
					.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
			menu.add(0, R.id.delete_lich_kham, Menu.NONE, "Tạo lịch hẹn")
					.setIcon(R.drawable.ic_edit)
					.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

			break;
		case R.id.lich_su_kham_chua_benh:
			menu.add(0, R.id.them_lich_su_kham, Menu.NONE,
					getResources().getString(R.string.them))
					.setIcon(R.drawable.ic_add)
					.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
			break;
		case Utils.DOCTOR_DETAILT:
			menu.add(0, R.id.update_doctor, Menu.NONE,
					getResources().getString(R.string.them))
					.setIcon(R.drawable.ic_edit)
					.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
			break;
		case Utils.ASSISTANT_DETAILT:
			menu.add(0, R.id.update_assistiant, Menu.NONE,
					getResources().getString(R.string.them))
					.setIcon(R.drawable.ic_edit)
					.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
			break;

		case R.id.lich_su_benh_cua_gia_dinh:
			menu.add(0, R.id.add_family_medical, Menu.NONE,
					getResources().getString(R.string.them))
					.setIcon(R.drawable.ic_add)
					.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
			break;
		case R.id.reply_message:
			menu.add(0, R.id.attach_file_reply, Menu.NONE,
					getResources().getString(R.string.dinh_kem))
					.setIcon(R.drawable.ic_add_tattack)
					.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
			break;
		case R.id.reply_message_doctor:
			menu.add(0, R.id.attach_file_reply_doctor, Menu.NONE,
					getResources().getString(R.string.dinh_kem))
					.setIcon(R.drawable.ic_add_tattack)
					.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
			break;
		case R.id.send_message_doctor:
			menu.add(0, R.id.attach_file_sendmessage_doctor, Menu.NONE,
					getResources().getString(R.string.dinh_kem))
					.setIcon(R.drawable.ic_add_tattack)
					.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
			break;
		case R.id.send_message:
			menu.add(0, R.id.attach_file_sendmessage, Menu.NONE,
					getResources().getString(R.string.dinh_kem))
					.setIcon(R.drawable.ic_add_tattack)
					.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
			break;
		case R.id.message_detailt:
			// if (FragmentMessages.newInstance().getCurrentNotification()
			// .getReply_for_notification_id() >= 0) {
			if (mOptionSend == Utils.REPLY_PATIENT) {
				menu.add(0, R.id.reply_message, Menu.NONE, mTitle)
						.setIcon(R.drawable.ic_send_holo_light)
						.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
			} else if (mOptionSend == Utils.REPLY_PATIENT_DOCTOR) {
				menu.add(0, R.id.reply_message_doctor, Menu.NONE, mTitle)
						.setIcon(R.drawable.ic_send_holo_light)
						.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
			}
			// }
			break;
		case R.id.quan_ly_bacsi:
			menu.add(0, R.id.them_bac_si, Menu.NONE, mTitle)
					.setIcon(R.drawable.ic_add)
					.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
			break;
		case R.id.cac_van_de_suc_khoe:
			menu.add(0, R.id.cac_van_de_suc_khoe, Menu.NONE, mTitle)
					.setIcon(R.drawable.ic_add)
					.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
			break;
		case R.id.quan_ly_tro_ly:
			menu.add(0, R.id.them_tro_ly, Menu.NONE, mTitle)
					.setIcon(R.drawable.ic_add)
					.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
			break;
		case R.id.bang_gia:

			menu.add(0, R.id.bang_gia, Menu.NONE, mTitle)
					.setIcon(R.drawable.ic_add)
					.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
			menu.add(0, R.id.edit_location_price, Menu.NONE, mTitle)
					.setIcon(R.drawable.ic_edit)
					.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
			break;
		case R.id.quang_li_hinh_anh:
			menu.add(0, R.id.quang_li_hinh_anh, Menu.NONE, mTitle)
					.setIcon(R.drawable.ic_add)
					.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
			break;
		default:
			break;
		}

		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public void onBackPressed() {
		finish();
	}

	public void setStyleSearch() {
		AutoCompleteTextView searchText = (AutoCompleteTextView) searchView
				.findViewById(R.id.abs__search_src_text);
		searchText.setHintTextColor(getResources().getColor(
				android.R.color.white));
		searchText.setTextColor(getResources().getColor(android.R.color.white));
		searchText.setTextSize(14);
	}

	@Override
	public boolean onSuggestionSelect(int position) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean onSuggestionClick(int position) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean onQueryTextSubmit(String query) {
		if (query.isEmpty())
			return false;
		Bundle bundle = new Bundle();
		bundle.putBoolean(Utils.CUSTOMBAR, false);
		bundle.putString(Utils.TITLE, "Tìm kiếm '" + query + "'");
		bundle.putString(Utils.KEY_SEARCH, query);

		if (mOptionMenu == R.id.lich_hen_doctor) {
			bundle.putInt(Utils.KEY, Utils.SEARCH_LICH_HEN_DOCTOR);
			Utils.getNewIntent(DetailtActivity.this, bundle);
		} else if (mOptionMenu == R.id.benh_nhan_doctor) {
			bundle.putInt(Utils.KEY, Utils.SEARCH_BENH_NHAN_DOCTOR);
			Utils.getNewIntent(DetailtActivity.this, bundle);
		} else {
			bundle.putInt(Utils.KEY, Utils.SEARCH_MESSAGE_DOCTOR);
			Utils.getNewIntent(DetailtActivity.this, bundle);
		}

		return false;
	}

	@Override
	public boolean onQueryTextChange(String newText) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void onDisplay(int type, Bundle data) {

		switch (type) {
		case Utils.DELETE_MESSAGE:
			mMode = startActionMode(new AnActionModeOfEpicProportions(
					Utils.DELETE_MESSAGE));
			break;
		case Utils.DELETE_PATIENTS:
			mMode = startActionMode(new AnActionModeOfEpicProportions(
					Utils.DELETE_PATIENTS));
			break;
		default:
			mOptionSend = data.getInt(Utils.KEY);
			invalidateOptionsMenu();
			break;
		}
	}

	private final class AnActionModeOfEpicProportions implements
			ActionMode.Callback {
		private int mOption;

		public AnActionModeOfEpicProportions(int option) {
			this.mOption = option;
		}

		@Override
		public boolean onCreateActionMode(ActionMode mode, Menu menu) {
			menu.add("Save").setIcon(R.drawable.ic_delete_black_24dp)
					.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

			return true;

		}

		@Override
		public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
			return false;
		}

		@Override
		public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
			if (mOption == Utils.DELETE_MESSAGE) {
				FragmentClinicMessages.newInstance().onDelete();
			} else if (mOption == Utils.DELETE_PATIENTS) {
				FragmentClinicListPatients.newInstance().onDelete();
			}
			mode.finish();
			return true;
		}

		@Override
		public void onDestroyActionMode(ActionMode mode) {
			FragmentClinicMessages.newInstance().setLongclick(false);
			FragmentClinicListPatients.newInstance().setLongclick(false);

		}
	}
}
